import json


def number_choose(s):
    try:
        return float(s)
    except ValueError:
        if "/" in s:
            s = s.split("/")
            try:

                return float(s[0]) / float(s[1])
            except ValueError:
                return False
        return False


new_question = json.load(open("new_question.json", encoding="utf-8"))
print(len(new_question))
calculation_symbols = ["+", "-", "*", "/", "//", "%"]
second_mathematics_practical_problems = []
for new_question in new_question:
    if len(new_question["number"]) == 1:
        continue
    if len(new_question["number"]) == 2:
        calculation = new_question["number"]
        answer = number_choose(new_question["answer"])
        if calculation[0] + calculation[1] == answer:
            new_question["label"] = 1
            second_mathematics_practical_problems.append(new_question)
        if calculation[0] - calculation[1] == answer:
            new_question["label"] = 2
            second_mathematics_practical_problems.append(new_question)

        if calculation[0] * calculation[1] == answer:
            new_question["label"] = 3
            second_mathematics_practical_problems.append(new_question)

        if calculation[0] / calculation[1] == answer:
            new_question["label"] = 4
            second_mathematics_practical_problems.append(new_question)
print(len(second_mathematics_practical_problems))
json.dump(second_mathematics_practical_problems,
          open("second_mathematics_practical_problem.json", "w", encoding="utf-8"), ensure_ascii=False, indent=3)
